var mainId;

window.onload = function () {
  mainId = getQuery("id");
  init()
};

async function init() {
    let info = await ajaxGet("/main/findById", {id: mainId});
    console.log(info);
    $("title").innerHTML = info.mainName;
    $("user").innerHTML = info.userBean.username;
    $("face").src = "/html/img/" + info.userBean.facePath;
    $("time").innerHTML = info.userBean.time;
    $("titleSpan").innerHTML = info.mainName;
    $("mainTime").innerHTML = info.mainTime;
    $("contentSpan").innerHTML = info.mainContent;

    let str = "";
    for (let i = 0; i < info.replyBeans.length; i++) {

        let replyBean = info.replyBeans[i];
        str += `<div style="display: flex; height:100px; border: 2px solid #4455aa;margin-top: 10px">
                    <div style="width: 300px;border-right: 2px solid #4455aa ">
                        头像: <img src="/html/img/${replyBean.userBean.facePath}" style="width: 40px;height: 40px;"><br>
                        回复人: ${replyBean.userBean.username} <br>
                        注册日期: ${replyBean.userBean.time} <br>
                    </div>
                    <div style="width: 500px;">
                        主题: <span>${replyBean.replyName}</span>@ <span>${replyBean.replyTime}</span><br><hr>
                        <span>${replyBean.replyContent}</span>
                    </div>
                </div>`;
    }
    $("replyDiv").innerHTML = str;
}

async function addReply() {
    let info = await ajaxGet("/reply/add",{
        replyName:$("replyName").value,
        replyContent:$("contentDiv").value,
        mainId: mainId
    });
    init();
}
